﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using www.serviciipeweb.ro.CDC;

namespace www.serviciipeweb.ro.CDCPS
{
    public class DataToShow
    {
        public DateTime DateModified;
        public string Operation;
    }
    [Cmdlet(VerbsCommon.Get, "CDCData", SupportsShouldProcess = true)]
    public class GetCaptures : Cmdlet
    {
        [Parameter(Position = 0, Mandatory = true)]
        public string ServerName
        {
            get;
            set;
        }
        [Parameter(Position = 0, Mandatory = true)]
        public string DatabaseName
        {
            get;
            set;
        }
        [Parameter(Position = 0, Mandatory = true)]
        public string TableName
        {
            get;
            set;
        }
        protected override void ProcessRecord()
        {
            FacadeCDC f = new FacadeCDC();
            f.ServerName = ServerName;
            f.DatabaseName = DatabaseName;
            f.TableName = TableName;
            List<DataToShow> l = new List<DataToShow>();
            foreach (TableChanges tc in f.Changes())
            {
                l.Add(new DataToShow() { DateModified = tc.Start, Operation = tc.SQLOperation.ToString() });
            }
            WriteObject(l);
        }

    }
}
